{% include 'admin/header.html' %}

<body>
  <div class="lyear-layout-web">
    <div class="lyear-layout-container">
      {% include 'admin/nav.html' %}

      <main class="lyear-layout-content">
        <div class="container-fluid">
          <div class="alert alert-info alert-dismissible fade show" role="alert">
            <i class="fas fa-info-circle mr-2"></i>
            当前页面为宿舍分配列表。

          </div>
          <div class="card shadow-lg mb-4">
            <header class="card-header d-flex justify-content-between align-items-center">
              <h4 class="card-title mb-0 text-primary">宿舍分配列表</h4>
              <a href="{{ url_for('main.allocate_dorm') }}" class="btn btn-outline-primary btn-sm">分配宿舍</a>
            </header>

            <div class="card-body">
              {% if allocate_lists %}
              <table class="table table-bordered table-hover">
                <thead>
                  <tr>
                    <th>用户名</th>
                    <th>宿舍名称</th>
                    <th>宿舍类型</th>
                    <th>入住时间</th>
                    <th>换宿时间</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                  {% for allocation in allocate_lists %}
                  <tr>
                    <td>{{ allocation.user.username }}</td>
                    <td>{{ allocation.dorm.name }}</td>
                    <td>{{ allocation.dorm.dorm_type.name }}</td>
                    <td>{{ allocation.check_in_time.strftime('%Y-%m-%d %H:%M') if allocation.check_in_time else '未入住' }}</td>
                    <td>{{ allocation.change_time.strftime('%Y-%m-%d %H:%M:%S') if allocation.change_time else '未更换' }}</td>
                    <td>
                      <a href="{{ url_for('main.change_dorm') }}" class="btn btn-outline-warning btn-sm">更换宿舍</a>
        {% if allocation.user %}
        <a href="{{ url_for('main.allocate_out', user_id=allocation.user.id) }}" class="btn btn-danger btn-sm">
            退宿
        </a>
        {% else %}
        <span class="text-muted">无分配</span>
        {% endif %}
                    </td>
                  </tr>
                  {% endfor %}
                </tbody>
              </table>
              {% else %}
              <p class="text-muted">当前没有宿舍分配记录。</p>
              {% endif %}
            </div>
          </div>
        </div>
      </main>
    </div>
  </div>

{% include 'admin/footer.html' %}
</body>
